package org.example.dev.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.example.dev.pojo.User;

import java.time.LocalDateTime;

@Mapper
public interface UserMapper extends BaseMapper<User> {

    @Insert("INSERT INTO User(username, password, phone, email, created_at, avatar) VALUES(#{username}, #{password}, #{phone}, #{email},#{createdAt}, #{avatar})")
    void insertUser(User user);

    @Update("UPDATE User SET password=#{password},updated_at=#{updatedAt} WHERE email=#{email}")
    void updatePassword(String password,LocalDateTime updatedAt,String email);

    @Update("UPDATE User SET phoneVerificationCode=#{phoneVerificationCode},updated_at=#{updatedAt} WHERE phone=#{phone}")
    void updatePhoneVerificationCode(String phone,String phoneVerificationCode, LocalDateTime updatedAt);

    @Select("select * from User WHERE email=#{email} ")
    User findUserByEmail(String email);

    @Select("select * from User WHERE phone=#{phone} ")
    User findUserByPhone(String phone);

    @Select("select * from User WHERE user_id=#{id} ")
    User findUserById(Integer id);

    @Update("UPDATE User SET avatar=#{avatar} WHERE user_id=#{id}")
    void updateAvatar(String avatar,Integer id);

    @Update("UPDATE User SET username=#{username},phone=#{phone},password=#{password} WHERE user_id=#{userId}")
    void update(String username,String phone,String password,Integer userId);
}
